public class LeetCode67 {
    public static void main(String[] args) {
//        String a = "11", b = "1";
        String a = "0";
        String b = "0";
        System.out.println(addBinary(a, b));
    }

    public static String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();

        int length = Math.max(a.length(), b.length());
        int carry = 0;

        for (int i = 0; i < length; i++) {
            carry += (a.length() - 1 - i >= 0) ? (a.charAt(a.length() - 1 - i) - '0') : 0;
            carry += (b.length() - 1 - i >= 0) ? (b.charAt(b.length() - 1 - i) - '0') : 0;
            sb.append(carry % 2);
            carry /= 2;
        }
        if (carry > 0) {
            sb.append('1');
        }
        return sb.reverse().toString();
    }
}
